import argparse

def parse_args():
    parser = argparse.ArgumentParser()
    """
    四个sub-command:
        install 安装docset
        search 查找docset
        download 下载docset
        list 列出所有的docset
    """
    parser.add_argument('--no-cache', help='cache the docset list for later use', action='store_true', default=False)
    parser.add_argument('--user', help='also use the docset in the user contribution list', action='store_true', default=False)
    subparsers = parser.add_subparsers(title='sub-commands', description='sub commands', dest='subcommand', required=True)

    install_parser = subparsers.add_parser('install', help='install docsets')
    install_parser.add_argument('doc_names', help='name of docset to install', nargs='+')
    install_parser.add_argument('--dest', help='docset dir of Zeal', default='~/.local/share/Zeal/Zeal/docsets')

    search_parser = subparsers.add_parser('search', help='look for docsets')
    search_parser.add_argument('doc_pattern', help='regex pattern of docset(ignore case)')

    download_parser = subparsers.add_parser('download', help='download docsets from Internet')
    download_parser.add_argument('doc_names', help='name of docset to download', nargs='+')
    download_parser.add_argument('--dest', help='dest dir to store the downloaded docset', default='.')

    list_parser = subparsers.add_parser('list', help='show all docsets')
    return parser.parse_args()

if __name__ == '__main__':
    print(parse_args())
